<cfsetting showdebugoutput="false"/>
<cfsilent>
<cfset KalendarEvent = LightWire.getTransient("KalendarEvent").init( argumentcollection=KalendarService.loadInput( URL, Form ) ) />
<cfset KalendarEvent = KalendarService.loadEvent( KalendarEvent )/>
<cfif KalendarConfig.getUseFCKEditor() is true>
	<cfset FCKEditor = LightWire.getTransient("FCKEditor") />
</cfif>
</cfsilent>
<cfif (KalendarEvent.getUserID() EQ session.user.getUserID()) OR (KalendarEvent.getRole() LT session.user.getRole() AND KalendarEvent.getIsPublic())>
	<cfset isEditable = true/>
<cfelse>
	<cfset isEditable = false/>
</cfif>
<cfif NOT (StructKeyExists(url,'EventID') AND isValid('uuid',url.EventID))>
	<cflocation addtoken="false" url="index.cfm"/>
</cfif>
<!--- TODO: add auth --->
<cfif StructKeyExists(form,'submit') AND form.submit EQ "delete record">
	<cfset KalendarService.loadCommand('DeleteRecord').execute(KalendarEvent,LightWire.getTransient("UserMsg").init())/>
	<script type="text/javascript">
		parent.tb_remove();
		parent.reloadView();
	</script>
	<cfabort/>
</cfif>
<cfif KalendarEvent.getUserID() NEQ session.user.getUserID() AND NOT KalendarEvent.getIsPublic()>
	<style type="text/css">
		* {
			font-family: Myriad Pro, arial, helvetica, sans-serif;
			font-size: 10pt;
			color: #887f6f;
		}
	</style>
	<div>This event does not exist or is unavailable.</div>
	<cfabort>
</cfif>
<cfcontent reset="true"/>
<cfoutput>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>Event Details</title>
		<link href="<cfoutput>#KalendarConfig.getCSSPath()#</cfoutput>kalendar_<cfoutput>#session.user.getRoleCode()#</cfoutput>.css" rel="stylesheet" type="text/css" />
		<link href="<cfoutput>#KalendarConfig.getAdminCSSPath()#</cfoutput>main.css" rel="stylesheet" type="text/css" />
		<cfif StructKeyExists(url,'mode') AND url.mode EQ 'edit'>
		<link rel="stylesheet" type="text/css" media="all" href="<cfoutput>#KalendarConfig.getJavascriptPath()#</cfoutput>jscalendar-1.0/calendar-win2k-cold-1.css" title="win2k-cold-1" />
		<!-- main calendar program -->
		<script type="text/javascript" src="<cfoutput>#KalendarConfig.getJavascriptPath()#</cfoutput>jscalendar-1.0/calendar.js"></script>
		<!-- language for the calendar -->
		<script type="text/javascript" src="<cfoutput>#KalendarConfig.getJavascriptPath()#</cfoutput>jscalendar-1.0/lang/calendar-en.js"></script>
		<!-- the following script defines the Calendar.setup helper function, which makes
		       adding a calendar a matter of 1 or 2 lines of code. -->
		<script type="text/javascript" src="<cfoutput>#KalendarConfig.getJavascriptPath()#</cfoutput>jscalendar-1.0/calendar-setup.js"></script>
		<script type="text/javascript">
			//<![CDATA[
			function checkIt() {
				
				if(Date.parse(document.eventForm.StartDate.value) > Date.parse(document.eventForm.EndDate.value)) {
					alert('Start Date must be the same as or before the end date');
					return false;	
				}
			}
			//]]>
		</script>
		</cfif>
	</head>
	<body id="eventDetailBody">
		<cfif (StructKeyExists(url,'mode') AND url.mode EQ 'edit') OR (StructKeyExists(form,'mode') AND form.Mode EQ 'edit')>
			<cflocation addtoken="false" url="#KalendarConfig.getKalendarAdminPath()#index.cfm?appaction=editRecord&eventID=#KalendarEvent.getEventID()#&fromPublic=true"/>
		<cfelse>
			<form method="post">
				<input type="hidden" name="mode" value="edit"/>
				<div>
					<cfset dateString = DateFormat(Request.Timezones.castFromUTC(KalendarEvent.getStartDate(),session.user.getTimezone()),'m/dd/yyyy')/>
					<cfif NOT KalendarEvent.getIsAllDayEvent()>
						<cfset dateString = dateString & " #Timeformat(Request.Timezones.castFromUTC(KalendarEvent.getStartDate(),session.user.getTimezone()))#"/>
					</cfif>
					<cfif Len(Trim(KalendarEvent.getEndDate()))>
						<cfset dateString = dateString & " - #DateFormat(Request.Timezones.castFromUTC(KalendarEvent.getEndDate(),session.user.getTimezone()),'m/dd/yyyy')#"/>
					</cfif>
					<cfif NOT KalendarEvent.getIsAllDayEvent() AND Len(Trim(KalendarEvent.getEndDate()))>
						<cfset dateString = dateString & " #Timeformat(Request.Timezones.castFromUTC(KalendarEvent.getEndDate(),session.user.getTimezone()))#"/>
					</cfif>
					<cfif KalendarEvent.getIsAllDayEvent()>
						<cfset dateString = dateString & " (all day event)">
					</cfif>
					<strong>Date</strong>: #dateString#<br/>
					<cfif len(trim(KalendarEvent.getLocation()))><strong>Location</strong>: #KalendarEvent.getLocation()#<br/></cfif>
					<cfif len(trim(KalendarEvent.getExternalURL()))><strong>Website</strong>: #KalendarEvent.getExternalURL()#<br/></cfif>
					<cfif len(trim(KalendarEvent.getContactName()))><strong>Contact</strong> Name: #KalendarEvent.getContactName()#<br/></cfif>
					<cfif len(trim(KalendarEvent.getContactEmail()))><strong>E-mail</strong>: #KalendarEvent.getContactEmail()#<br/></cfif>
					<cfif len(trim(KalendarEvent.getContactPhone()))><strong>Phone</strong>: #KalendarEvent.getContactPhone()#<br/></cfif>
					<div class="eventDescription"><p>#KalendarEvent.getDescription()#</p></div>
				</div>
				<cfif isEditable>
					<div style="text-align:center; margin-top: 19px;"><input name="updateRecord" type="submit" value="edit record" class="button" /></div>
				</cfif>
			</form>
		</cfif>
	</body>
</html>
</cfoutput>